package es.juanc.rt;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class RuntimeTest {

	public static void main( String[] args ) throws Exception {

		System.out.println( "INICIO ..." );

		System.out.println( System.getenv() );
		System.out.println( System.getenv().get("JAVA_HOME") );

		//Process process = Runtime.getRuntime().exec( "/home/juanc/WORKSPACES/wks_pruebas/Ejemplos/exe.sh" );
		Process process = Runtime.getRuntime().exec( // preguntar JL, el Idx
				new String[] { "/home/juanc/WORKSPACES/wks_pruebas/Ejemplos/exe.sh" } ,
				new String[] { "JAVA_HOME=/usr/lib/jvm/java-6-sun" } );
		//Process process = Runtime.getRuntime().exec(
		//		"java -cp /home/juanc/WORKSPACES/wks_pruebas/Ejemplos/bin es.juanc.rt.Externo" );

		//System.out.println( "RC: " + process.exitValue() );
		System.out.println( "*** RC: " + process.waitFor() );

		System.out.println( "*** Standat output" );

		InputStreamReader isw = new InputStreamReader( process.getInputStream() );
		BufferedReader br = new BufferedReader( isw );
		String line = "";
		while ( ( line = br.readLine() ) != null ) {
			System.out.println( line );
		}
		System.out.println( "*************" );

		System.out.println( "*** Error output" );

		isw = new InputStreamReader( process.getErrorStream() );
		br = new BufferedReader( isw );
		line = "";
		while ( ( line = br.readLine() ) != null ) {
			System.out.println( line );
		}
		System.out.println( "*************" );

		System.out.println( "... FIN" );
	}
}